<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>判断某年某月有多少天</title>
    <script>
      function getDays(year, month) {
        let days
        //判断年份是否合法
        if (!isNaN(year) && year.length == 4) {
          //判断月份是否合法
          if (!isNaN(month) && month >= 1 && month <= 12) {
            //判断和年份来获取具体的天数
            if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
              days = 31
            } else if (month == 4 || month == 6 || month == 9 || month == 11) {
              days = 30
            } else {
              //判断年份是否是闰年
              if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
                days = 29
              } else {
                days = 28
              }
            }
            /*  switch (month) {
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
              days = 31
              break
            case 4:
            case 6:
            case 9:
            case 11:
               days = 30
              break
            case 2:
              //判断年份是否是闰年
              if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
                days = 29
              } else {
                days = 28
              }
          } */
          } else {
            alert('请输入正确的月份!')
          }
        } else {
          alert('请输入正确的年份!')
        }
        return days
      }
    </script>
  </head>
  <body></body>
</html>
